package com.woniuxy.happylife.controller;

import com.woniuxy.happylife.entity.MallRemark;
import com.woniuxy.happylife.entity.ResponseEntity;
import com.woniuxy.happylife.service.CommentsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author:roger
 * @Date:2022/2/19 16:19:55
 * @Description:
 */
@RestController
@RequestMapping("/comments")
public class CommentsController {

    @Autowired
    CommentsService commentsService;
    //某人在哪个商品里发布一条评论
    @PostMapping ("/")
    public ResponseEntity<Integer> publish(@RequestBody MallRemark mallRemark){
        return new ResponseEntity<Integer>(200,"发布评论成功",commentsService.publish(mallRemark));
    }
    //根据gid查出所有评论,
    @GetMapping("/{gid}")
    public ResponseEntity<List<MallRemark>> getBygid(@PathVariable("gid") int gid){
        return new ResponseEntity<List<MallRemark>>(200,"查询所有的评论和对应评论人",commentsService.getBygid(gid));
    }
    //根据gid查询该商品的评论数
    @GetMapping("/all/{gid}")
    public ResponseEntity<Integer> getNumsBygid(@PathVariable("gid") int gid){
        return new ResponseEntity<Integer>(200,"查询出总评论数",commentsService.getNumsBygid(gid));
    }
}
